package pers.liyan.shi.manager.common;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;

/**
 *  全局Controller层异常处理类
 * @author ShiLY
 */
@ControllerAdvice
@RestController
public class GlobalExceptionResolver {

    /**
     *处理所有不可知异常
     * @param e 异常
     * @return json结果
     */
    @ExceptionHandler(Exception.class)
    public Result handleException(Exception e) {
        return Result.fail(e.getMessage());
    }

    /**
     * 处理业务异常
     */
    @ExceptionHandler(BusinessRuntimeException.class)
    public Result handleBusinessException(BusinessRuntimeException e) {

        Result result = new Result();
        result.setCode(e.getCode());
        result.setMessage(e.getMessage());
        return result;

    }

}